package byj.com.meishi.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import byj.com.meishi.R;

/**
 * Created by Administrator on 2016/9/19 0019.
 */
public class ToggleListViewAdapter extends BasicAdapter<String>{
    private List<String> toggleTitle;
    private List<Integer> imgIds;
    public ToggleListViewAdapter(List<String> list) {
        super(list);
        toggleTitle=list;
    }
    public ToggleListViewAdapter(List<String> list,List<Integer> imgId){
        this(list);
        imgIds=imgId;
        notifyDataSetChanged();
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {

        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.togglistview_item
                    , viewGroup, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.img.setBackgroundResource(imgIds.get(i));
        holder.tv.setText(toggleTitle.get(i));
        return convertView;
    }

    class ViewHolder{
        ImageView img;
        TextView tv;
        public ViewHolder(View view){
            img= (ImageView) view.findViewById(R.id.toggle_list_iv);
            tv= (TextView) view.findViewById(R.id.toggle_list_tv);
        }
    }
}
